<?php


namespace app\admin\system\controller;


use app\common\controller\BaseAdminController;
use app\common\service\ConfigService;
use stdClass;
use support\exception\BadException;

class ConfigController extends BaseAdminController
{
    protected $noNeedRight = ['*'];

    public function getConfig()
    {
        $key = input('key');
        if (!$key) {
            throw new BadException("参数异常");
        }
        return $this->success(ConfigService::getConfig($key) ?: new stdClass());
    }

    public function getData()
    {
        $key = input('key');
        if (!$key) {
            throw new BadException("参数异常");
        }
        return $this->success(ConfigService::getData($key));
    }

    public function setConfig()
    {
        $key = input('key');
        $value = input('value');
        $remark = input('remark', "");

        if (!$key) {
            throw new BadException("参数异常");
        }
        ConfigService::setConfig($key, $value, $remark);
        return $this->success();
    }
}